package com.example.hyw.szysteam.view;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;

import com.example.hyw.szysteam.POJO.UserInfo;
import com.example.hyw.szysteam.R;
import com.example.hyw.szysteam.presenter.CreateClassPresenter;
import com.example.hyw.szysteam.utils.ShowTips;
import com.qmuiteam.qmui.widget.dialog.QMUITipDialog;
import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton;

/**
 * Created by HYW on 2018/6/7.
 */

public class CreateClassDialog extends DialogFragment {
    View view;
    EditText editClassName;
    QMUIRoundButton createClass;
    private CreateClassPresenter createClassPresenter=new CreateClassPresenter(this);

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view=inflater.inflate(R.layout.fragment_createclass,container,false);
        return view;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView();
    }

    public void initView(){
        editClassName=view.findViewById(R.id.input_classname);
        createClass=view.findViewById(R.id.button_creatclass);
        createClass.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(editClassName.getText().toString()!=""){
                    createClassPresenter.createClass(UserInfo.getEmail(),editClassName.getText().toString(),UserInfo.getName());
                }else {
                    ShowTips.show(QMUITipDialog.Builder.ICON_TYPE_INFO, "请输入班级名字", createClass, getContext());
                }
            }
        });
    }
    public void createSuccess(String invitecode){
        CreateClassSuccessDialog createClassSuccessDialog=new CreateClassSuccessDialog();
        createClassSuccessDialog.setInvitecode(invitecode);
        createClassSuccessDialog.show(getActivity().getSupportFragmentManager(),"CreateClassSuccess");
        this.dismiss();
    }
}
